@echo off
cls

call .\definePath.bat

	set COMPILE=
	if "%1"=="clean" (
        set COMPILE=clean
    ) else if "%1"=="data" (
        set COMPILE=data
	) else if "%1"=="debug" (
        set COMPILE=debug
	) else if "%1"=="release" (
        set COMPILE=release
    ) else if "%1" == "copy_porting" (
		set COMPILE=copy_porting
	) else (
		echo 	make parameter [build]
		echo   	parameter is one of
		echo    clean    			: clean all at working and assets
		echo    data    			: build all data and copy into assets
		echo    debug    			: build debug android and install
		echo    release  			: build release android and install
		echo    copy_porting   		: copy src in to jni
	)
	
	if "%COMPILE%"=="clean" (
		del /Q %WORKDIRECTORY%\*.*
		del /Q %ASSETS_PATH%\*.*
		del /Q %JNI_PATH%\*.cpp
		del /Q %JNI_PATH%\*.h
		echo ..................CLEAN DONE
	)else if "%COMPILE%"=="data" (
		if not exist "%WORKDIRECTORY%"	(
			mkdir "%WORKDIRECTORY%"		
		)
		echo ..................copy data to working
		rem sprite
		dir /B/S "%MASTER_DATA%\sprites\*.*"|FINDSTR /V "\.svn"|FINDSTR "\.sprite" > #src_file.txt
		dir /B/S "%MASTER_DATA%\sprites\*.*"|FINDSTR /V "\.svn"|FINDSTR "\.png" >> #src_file.txt
		rem font
		dir /B/S "%MASTER_DATA%\fonts\*.*"|FINDSTR /V "\.svn"|FINDSTR "\.sprite" >> #src_file.txt
		dir /B/S "%MASTER_DATA%\fonts\*.*"|FINDSTR /V "\.svn"|FINDSTR "\.png" >> #src_file.txt
		rem list
		dir /B/S "%MASTER_DATA%\*.*"|FINDSTR /V "\.svn"|FINDSTR "\.list" >> #src_file.txt
		
		rem GUI
		dir /B/S "%MASTER_DATA%\gui\*.*"|FINDSTR /V "\.svn"|FINDSTR "\.game" >> #src_file.txt
		dir /B/S "%MASTER_DATA%\gui\*.*"|FINDSTR /V "\.svn"|FINDSTR "\.gts" >> #src_file.txt
		dir /B/S "%MASTER_DATA%\gui\*.*"|FINDSTR /V "\.svn"|FINDSTR "\.level" >> #src_file.txt
		
		rem text
		dir /B/S "%MASTER_DATA%\text\*.*"|FINDSTR /V "\.svn"|FINDSTR "\.xls" >> #src_file.txt	
		
		rem shader		
		dir /B/S "%MASTER_SRC%\*.*"|FINDSTR /V "\.svn"|FINDSTR "\.fsh" >> #src_file.txt		
		dir /B/S "%MASTER_SRC%\*.*"|FINDSTR /V "\.svn"|FINDSTR "\.vsh" >> #src_file.txt	
		
		
		rem clean data 
		del /Q %WORKDIRECTORY%\*.*
		for /F %%i in (#src_file.txt) do (		
			xcopy /S /Y "%%i" %WORKDIRECTORY% > NUL
		)
		del /F/Q/S #src_file.txt > NUL
		
		xcopy /S /Y "%TOOL_BUILD_SPRITE%\BuildSprite.exe" %WORKDIRECTORY%\ > NUL
		xcopy /S /Y "%TOOL_BUILD_FONT%\BuildFont.exe" %WORKDIRECTORY%\ > NUL
		xcopy /S /Y "%TOOL_BUILD_GUI%\BuildGui.exe" %WORKDIRECTORY%\ > NUL
		xcopy /S /Y "%TOOL_BUILD_TEXT%\BuildText.exe" %WORKDIRECTORY%\ > NUL
		
		echo .............Read and write sprite list.......................
		cd %WORKDIRECTORY%		
		rem build sprite
		call .\BuildSprite.exe sprites.list
		rem build font
		call .\BuildFont.exe fonts.list
		rem build gui
		call .\BuildGui.exe gui.game
		rem build text
		call .\BuildText.exe text.xls
		
		rem copy text.gts to text
		xcopy /S /Y %WORKDIRECTORY%\text.gts %MASTER_DATA%\text > NUL
		
		rem delete after building has finished
		del /Q %WORKDIRECTORY%\BuildSprite.exe
		del /Q %WORKDIRECTORY%\BuildFont.exe
		del /Q %WORKDIRECTORY%\BuildGui.exe
		del /Q %WORKDIRECTORY%\BuildText.exe
		del /Q %WORKDIRECTORY%\*.sprite
		del /Q %WORKDIRECTORY%\*.list
		del /Q %WORKDIRECTORY%\*.gts
		del /Q %WORKDIRECTORY%\*.game
		del /Q %WORKDIRECTORY%\*.level
		del /Q %WORKDIRECTORY%\*.xls
		
		cd %MAKE_PATH%
		echo ...........Build sprite DONE.............
		
		rem copy data in to asset
		Rem shaders
		dir /B/S "%MASTER_SRC%\*.*"|FINDSTR /V "\.svn"|FINDSTR "\.fsh" >> #src_file.txt		
		dir /B/S "%MASTER_SRC%\*.*"|FINDSTR /V "\.svn"|FINDSTR "\.vsh" >> #src_file.txt	
		rem copy .pack and .png
		dir /B/S "%WORKDIRECTORY%\*.*"|FINDSTR /V "\.svn"|FINDSTR "\.pack" >> #src_file.txt		
		dir /B/S "%WORKDIRECTORY%\*.*"|FINDSTR /V "\.svn"|FINDSTR "\.png" >> #src_file.txt		
		
		if not exist "%ASSETS_PATH%"	(
			mkdir "%ASSETS_PATH%"		
		)
		for /F %%i in (#src_file.txt) do (		
			xcopy /S /Y "%%i" %ASSETS_PATH% > NUL
		)
		del /F/Q/S #src_file.txt > NUL
		echo ..........Copy in Assets DONE.............
		
	) else if "%COMPILE%"=="debug" (
		cd %PORTING_PATH%
		ant debug install
		cd %MAKE_PATH%
	) else if "%COMPILE%"=="release" (
		echo #define DEBUG 0 >> %JNI_PATH%\%RESOLUTION_BUILD%.h
		cd %PORTING_PATH%
		ant debug install
		cd %MAKE_PATH%
    ) else if "%COMPILE%"=="copy_porting" (
		echo ..................copy src to porting/jni
		dir /B/S "%MASTER_SRC%\*.*"|FINDSTR /V "\.svn"|FINDSTR "\.h" > #src_file.txt
		dir /B/S "%MASTER_SRC%\*.*"|FINDSTR /V "\.svn"|FINDSTR "\.cpp" >> #src_file.txt
		dir /B/S "%WORKDIRECTORY%\*.*"|FINDSTR /V "\.svn"|FINDSTR "\.h" >> #src_file.txt
		dir /B/S "%WORKDIRECTORY%\*.*"|FINDSTR /V "\.svn"|FINDSTR "\.cpp" >> #src_file.txt
				
		for /F %%i in (#src_file.txt) do (		
			xcopy /S /Y "%%i" %JNI_PATH% > NUL
		)		
		del /F/Q/S #src_file.txt > NUL
		
		cd %MAKE_PATH%
		echo ...........Copy src to jni DONE...........
		
	)
	
	
    